<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobprofile_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	function users_getall($userid)
	{
	   
		/*$users = $this->db->get('users',$userid);
	    return $users->result();*/
	}
	function users_get()
	{
	    $users_get = $this->db->get('users');
	    return $users_get->result();
	}

	function designation_getall()
	{
	    $query = $this->db->get('user_type');
	    return $query->result();
	}
	function hobbies_getall()
	{
	    $query2 = $this->db->get('hobbies');
	    return $query2->result();
	}
	/*function skills_insert($insert)
	{
		//print_r($insert);
		//exit;
	   $this->db->insert('skills',$insert);
	 	 //  return $this->db->insert($add);	
	}*/
	public function skills_insert($designation_id,$skillname,$file_name)
	{
 	$this->db->insert('skills',array('user_type_id'=>$designation_id,'name'=>$skillname,'image'=>$file_name));	
	}
	public function hobbies_insert($hobbyname,$file_name)
	{
 	$this->db->insert('hobbies',array('name'=>$hobbyname,'location'=>$file_name));	
	}
	function skills_getall()
	{
	    
		$this->db->select('skills.*,user_type.name AS titlename,skills.name AS skillname');
    	$this->db->from('user_type');
    	$this->db->join('skills', 'user_type_id = user_type.id');
    	$getskills = $this->db->get();
		return $getskills->result();
	}
	function efficiency_insert($insert)
	{
		//print_r($insert);
		//exit;
	    $this->db->insert('efficiency',$insert);
	 	//  return $this->db->insert($add);	
	}
	public function efficiency_delete($delete_id)
	{
		//echo $delete_id;exit;
		$this->db->delete('efficiency',array('id'=>$delete_id));
	}
	public function skills_delete($delete_id)
	{
		$this->db->delete('skills',array('id'=>$delete_id));
	}
	public function hobbies_delete($delete_id)
	{
		$this->db->delete('hobbies',array('id'=>$delete_id));
	}
	public function tools_delete($delete_id)
	{
		$this->db->delete('tools',array('id'=>$delete_id));
	}
	function efficiency_getall()
	{
		$this->db->select('efficiency.*,user_type.name AS titlename,efficiency.name AS efficiencyname');
    	$this->db->from('user_type');
    	$this->db->join('efficiency', 'user_type_id = user_type.id');
    	$getefficiency = $this->db->get();
		return $getefficiency->result();
	}
	function tools_insert($insert)
	{
		//print_r($insert);
		//exit;
	    $this->db->insert('tools',$insert);
	 	
	}
	function tools_getall()
	{
	  
		$this->db->select('tools.id,user_type.name AS titlename,tools.name AS toolname');
    	$this->db->from('user_type');
    	$this->db->join('tools', 'user_type_id = user_type.id');
    	$gettools = $this->db->get();
		return $gettools->result();
	}
	
	public function get_efficiency_by_user_type_id()
	{
		$this->db->select('user_type.*,efficiency.*');
		$this->db->from('user_type');
		$this->db->join('efficiency', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}
		
	public function get_efficiency_by_user_type($user_type_id)
	{
	
		$this->db->select('user_type.*,efficiency.*');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('efficiency', 'user_type_id = user_type.id');
		return $this->db->get()->result();	
	}
	
	
	function efficiency_custom_insert($insert)
	{
		
	$get_id = $this->db->get_where('efficiency_custom',array('user_id'=>$this->input->post('users')))->result();
		//$a=count($get_id); echo $a;
		if(count($get_id)==0)
					{	
		foreach($insert as $efficiency)
		{
					$this->db->insert('efficiency_custom',$efficiency);
		}}else{	
		foreach($insert as $update)
		{
			$this->db->update('efficiency_custom',array('level'=>$update['level'],'custom_subfields'=>$update['custom_subfields']),array('user_id'=>$update['user_id'],'name'=>$update['name']));
			//echo $this->db->last_query();
		}}
		//exit;
	}
	
	function skill_custom_insert($insert)
	{
		
	$get_id = $this->db->get_where('skills_custom',array('user_id'=>$this->input->post('users')))->result();
		//$a=count($get_id); echo $a;
		if(count($get_id)==0)
					{	
		foreach($insert as $skills)
		{
					$this->db->insert('skills_custom',$skills);
		}}else{	
		foreach($insert as $update)
		{
			$this->db->update('skills_custom',array('level'=>$update['level'],'skills_id'=>$update['skills_id']),array('user_id'=>$update['user_id'],'name'=>$update['name']));
			//echo $this->db->last_query();
		}}
		//exit;
	}
	
	function tool_custom_insert($insert)
	{
		
	$get_id = $this->db->get_where('tools_custom',array('user_id'=>$this->input->post('users')))->result();
		//$a=count($get_id); echo $a;
		if(count($get_id)==0)
					{	
		foreach($insert as $tools)
		{
					$this->db->insert('tools_custom',$tools);
		}}else{	
		foreach($insert as $update)
		{
			$this->db->update('tools_custom',array('level'=>$update['level']),array('user_id'=>$update['user_id'],'name'=>$update['name']));
			//echo $this->db->last_query();
		}}
		//exit;
	}
	
	public function get_skills_by_user_type_id($user_type_id)
	{
		$this->db->select('user_type.*,skills.*');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('skills', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}
	public function get_tools_by_user_type_id($user_type_id)
	{
		$this->db->select('user_type.*,tools.name');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('tools', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}

	public function create_efficiency($insert)
	{
		$this->db->insert('efficiency_custom',$insert);
	}
	
	public function get_all_profilelist_by_user_id()
	{
		//return $this->db->get_where('user_type',array('id'=>@$id))->row_array();
	}
	


	function user_hobbies_insert($insert)
	{
		
				foreach($insert as $hobbies)			
				{
				$this->db->insert('user_hobbies',$hobbies);
				}
				
	}
	
	function skills_getall_by_id($id)
	{
	    $this->db->select('skills_custom.*,users.username AS username,skills_custom.name AS skillname');
    	$this->db->from('users');	
    	$this->db->join('skills_custom', 'user_id = users.id');
		$this->db->where('skills_custom.user_id =',$id);
    	$getskillsid = $this->db->get();
		return $getskillsid->result();
	}
	function tools_getall_by_id($id)
	{
	    $this->db->select('tools_custom.*,users.username AS username,tools_custom.name AS toolname');
    	$this->db->from('users');
    	$this->db->join('tools_custom', 'user_id = users.id');
		$this->db->where('tools_custom.user_id =',$id);
    	$gettoolsid = $this->db->get();
		return $gettoolsid->result();
	}
	function efficiency_getall_by_id($id)
	{
		
	    $this->db->select('efficiency_custom.*,users.username AS username,efficiency_custom.name AS efficiencyname');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
    	$getefficiencyid = $this->db->get();
		return $getefficiencyid->result();
	}

	function hobbies_getall_by_id($id)
	{
		$this->db->select('user_hobbies.*');
    	$this->db->from('users');
    	$this->db->join('user_hobbies', 'user_id = users.id');
		$this->db->where('user_hobbies.user_id =',$id);
		
	   
		$hobbies = $this->db->get();
	    return $hobbies->result();
	}
	
		
	function efficiencychart($id)
	{
		$this->db->select('efficiency_custom.*,');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
		$efficiencychart = $this->db->get();
		return $efficiencychart->result();
/*
           foreach($efficiencychart as $row) { // return result as assoc array to use in calendar
            echo $row['name'];
            echo $row['level'];*/
       

      // return $efficiencychart->result();
        
	}
	
	function efficiencyfields($id)
	{
		$this->db->select('efficiency_custom.*,');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
		$efficiencyfields = $this->db->get();
		return $efficiencyfields->result_array();
/*
           foreach($efficiencychart as $row) { // return result as assoc array to use in calendar
            echo $row['name'];
            echo $row['level'];*/
       

      // return $efficiencychart->result();
        
	}
	
	
	function skillschart($id)
	{
		$this->db->select('skills_custom.name,skills_custom.level');
    	$this->db->from('users');
    	$this->db->join('skills_custom', 'user_id = users.id');
		$this->db->where('skills_custom.user_id =',$id);
		$skillschart = $this->db->get();
		return $skillschart->result();
	}
	
	function toolschart($id)
	{
		$this->db->select('tools_custom.name,tools_custom.level');
    	$this->db->from('users');
    	$this->db->join('tools_custom', 'user_id = users.id');
		$this->db->where('tools_custom.user_id =',$id);
		$toolschart = $this->db->get();
		return $toolschart->result();
	}
	
	function hobbyimage($id)
	{
		$this->db->select('user_hobbies.*,hobbies.*');
    	$this->db->from('hobbies');
    	$this->db->join('user_hobbies', 'hobbies_id = hobbies.id');
		$this->db->where('user_hobbies.user_id =',$id);
		$hobbyimage = $this->db->get();
		return $hobbyimage->result();
	}
	
	function skillsimage($id)
	{
		$this->db->select('skills_custom.*,skills.*');
    	$this->db->from('skills');
    	$this->db->join('skills_custom', 'skills_id = skills.id');
		$this->db->where('skills_custom.user_id =',$id);
		$skillsimage = $this->db->get();
		return $skillsimage->result();
	}
	
	function userdetails($id)
	{
		$this->db->select('users.*');
    	$this->db->from('users');
    	$this->db->where('id =',$id);
		$userdetails = $this->db->get();
		return $userdetails->result();
	}
	function designationbyid($id)
	{
		$this->db->select('users_groups.*,user_type.*');
    	$this->db->from('user_type');
    	$this->db->join('users_groups', 'user_type_id = user_type.id');
		$this->db->where('users_groups.user_id =',$id);
		$designationbyid = $this->db->get();
		return $designationbyid->result();
	}




}
